// 关于用户请求
import request from '@/utils/request.js'
// store === this.$store
// this.$store.state.user
// store.state.user

/**
 * 用户登录
 * @param {Object} data { mobile: '', code: '' }
 */

// export const login = data => {
//   return request.post('/v1_0/authorizations', data)
// }
export const login = data => {
  return request({
    method: 'POST',
    url: '/v1_0/authorizations',
    data: data
  })
}

/**
 * 获取验证码
 * @param {String | Number} mobile 手机号
 * @returns
 */
export const sendCode = mobile => {
  return request({
    method: 'GET',
    url: '/v1_0/sms/codes/' + mobile
  })
  // return request.get('/v1_0/sms/codes/' + mobile, {
  //   params: {
  //     name: ''
  //   }
  // })
}

/**
 * 获取用户自己信息
 * @returns
 */
export const getUserInfo = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user'
  })
}

/**
 * 获取用户频道列表
 * @returns
 */
export const getUserChannels = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user/channels'
  })
}

/**
 * 添加关注用户
 * @param {*} target 关注的用户id
 * @returns
 */
export const addFollowUser = target => {
  return request({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target
    }
  })
}

/**
 * 删除关注用户
 * @param {*} target 关注的用户id
 * @returns
 */
export const removeFollowUser = target => {
  return request({
    method: 'DELETE',
    url: '/v1_0/user/followings/' + target
  })
}

/**
 * 获取用户自己信息
 * @returns
 */
export const getUserDetail = () => {
  return request({
    method: 'GET',
    url: '/v1_0/user/profile'
  })
}

/**
 * 修改用户资料
 * @param {*} data {}
 * @returns
 */
export const setUserProfile = data => {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/profile',
    data
  })
}

/**
 * 设置用户头像或者身份证照片等等
 * @param {*} data {}
 * @returns
 */
export const setUserImage = data => {
  return request({
    method: 'PATCH',
    url: '/v1_0/user/photo',
    data
  })
}
